module(..., package.seeall)

local imgPath = "images/"
function popup(monster_id, localGroup)
	local monDetailGrp = display.newGroup()
	local bdr2 = display.newRect( 0, 0, display.contentWidth, display.contentHeight )
	bdr2:setReferencePoint(display.BottomLeftReferencePoint) 
	bdr2.strokeWidth = 1
	bdr2:setFillColor(100, 100, 100)
	bdr2:setStrokeColor(0, 222, 222)
	bdr2.alpha = 0.9
	
	local fncProtection2 = function( event )
		return true
	end	
	bdr2:addEventListener( "touch", fncProtection2 )
	localGroup:insert(bdr2)
	
	local w, h = display.contentWidth, display.contentHeight
	local background = display.newImage( "background3.png" )
	background.xScale = 1
	background.yScale = 1
	background.alpha = 1
	--close button
	local closeBtn = display.newImage("images/cross_32.png") 
	function closeBtn:tap(e)  
		--bdr.isVisible = false;
		print("pangkah popup monster!!!")
		if monDetailGrp.numChildren > 0 then
				for i=monDetailGrp.numChildren,1,-1 do
				   monDetailGrp[i]:removeSelf()
				   monDetailGrp[i] = nil
				end
		end 
		localGroup:remove(monDetailGrp)
		monDetailGrp = nil
		return true
	end  
	closeBtn:addEventListener( "tap", closeBtn )
	--popup title
	local popupTitle = display.newText( "MONSTER : "..monster_id, 120, 5, native.systemFontBold, 20 )
	--add monster image
	local monImg = display.newImage("images/jessica_600x900.jpg")
	monImg.x = 160
	monImg.y = 255
	monImg.xScale = 0.5
	monImg.yScale = 0.5

	--add to grp
	monDetailGrp:insert(bdr2)
	monDetailGrp:insert(background)
	monDetailGrp:insert(monImg)
	monDetailGrp:insert(closeBtn)
	monDetailGrp:insert(popupTitle)
	--add to main grp
	
	-- for row in db:nrows("SELECT * FROM monster") do
	  -- local text = row.word_en.." "..row.word_my
	  -- local t = display.newText(text, 20, 30 * row._id, null, 16)
	  -- t:setTextColor(255,0,255)
	  -- monDetailGrp:insert(t)
	-- end
	localGroup:insert(monDetailGrp)

	function freeze(event)
		return true
	end
	monDetailGrp:addEventListener( "tap", freeze )
end

